package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/6/29 10:02
 * @Version 1.0
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {

    @Autowired
    SecurityManager securityManager;

//    @Autowired
//    GlobalSessionHolder sessionHolder;

    //发送这个请求时，并没有携带任何的请求参数，你怎么知道应该去查询哪个用户的订单信息？？？session
    @RequiresAuthentication
    @GetMapping("index")
    public Object index(){
        SecurityUtils.setSecurityManager(securityManager);

        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        MarketUser user = (MarketUser) session.getAttribute("user");
        System.out.println(user);
        return null;
    }
}
